package com.aotain.project;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.log4j.Logger;

import com.aotain.apollo.IDCIPSegment;
import com.aotain.common.CommonFunction;


/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
    	
    	
    	
    	
//    	String dbhost = "192.168.50.155";
//		String DBJSON="{\"driverClassName\":\"oracle.jdbc.driver.OracleDriver\","
//				+ "\"maxActive\":\"200\",\"maxIdle\":\"50\",\"maxWait\":\"10000\","
//				+ "\"name\":\"sds\",\"password\":\"h16aug8v3w\",\"queryTimeout\":\"60\","
//				+ "\"type\":\"javax.sql.DataSource\",\"url\":\"jdbc:oracle:thin:@"+ dbhost +":1521:bsmp\","
//				+ "\"userName\":\"sds\",\"validationQuery\":\"select sysdate from dual\"}";
//			
//		final IDCIPSegment ipseg = new IDCIPSegment();
//		ipseg.GetIDCIPSegment(DBJSON);
		
//		String a = "%201=1%20|%201=2%20|%20a-a%20|%20a=b%20|%20and%20|%20or%20|exec|execute|insert%20|select%20|%20from%20|delete%20|update%20|alter%20|create%20|drop%20|union|into|substr|ascii|%20count|chr|sleep|char|nchar|char_length|asc|truncate|declare|backup|%20between%20|%20order%20|ord|%20group%20|%20by%20|hiving|sum|Unicode|substring|master|hex|unhex|xp_cmdshell|sp_server_info|restore|quotename|db_name|database|version|sysobjects|msysobjects|session_user|curren_user|is_srvrolemember|is_member|sysdatabases|syscolumns|user_users|dba_tables|user_object";
//		String url = "comment.ifeng.com/get.php?callback=nopassCallBack&CoderBy=create_time&order=DES&docUrl=http%3A%2F%2Ftech.ifeng.com%2Fa%2F20170515%2F44613772_0.shtml&format=js&job=11&p=1&pageSize=20&callback=nopassCallBack&skey=6a2e15&sid=&cmtids=";
//		
//		int num = CommonFunction.MatchSQLInjection(url,a);
    	Double p = 0.0;
    	Double a = -Math.log(p)*p;
    	System.out.println(a);
		
		//读取域名备案数据
//		 ApolloConfig ap = new ApolloConfig(DBJSON);
//		 final HashMap<String,String> domainMap = ap.getDomainRecord();
		 
		 
//    	DBConfigInit DB = new DBConfigInit("D:\\workspace\\Hades-Z\\hades-main\\hades-project\\config\\dbconfig.ini");
//		String dbJson = DB.getDBObjectJson();
//		Logger.getLogger(ApolloConfig.class).info("ApolloConfig:" + dbJson);
//		    	
//		DbPool dbpool = new DbPool(dbJson);
//		Connection conn = dbpool.getConnJson();
//		
//		HashMap<String,Long> mapIPList = new HashMap<String,Long>();
//		ResultSet rs = null;
//		try
//		{
//			PreparedStatement ps = null;
//			ps= conn.prepareStatement("SELECT IP,UPDATETIME FROM METIS_IP_LIST");
//				       
//			rs=ps.executeQuery();
//	        while(rs.next()){
//	        	String ip = rs.getString("IP");
//	        	Date updatetime = rs.getTimestamp("UPDATETIME");
//	        	mapIPList.put(ip,updatetime.getTime());
//	        }
//	       
//		} catch (Exception ex) {
//			Logger.getLogger(IPScanUpdate.class).error("get ip list error",ex);
//		} finally {
//			CommonDB.closeDBConnection(conn, null, rs);
//		}
		

    	
    	
    	
    	
    	
     }
    


	public static int  matchRuleBase(String url){
		
		int matchNum = 0;
		try{				
			if(url.isEmpty()) return matchNum;
			url = URLDecoder.decode(url,"utf-8").toLowerCase();
			//if(url.indexOf("?") == -1) return matchNum;
			//url = url.substring(url.indexOf("?"),url.length()).replaceAll("'", "");
			String rgx = "<script>|</script>";
			Pattern pattern = Pattern.compile(rgx); 
			Matcher m = pattern.matcher(url);
			ArrayList<String> list = new ArrayList<String>(); 
			while(m.find()) {
				if(!list.contains(m.group())) 
					list.add(m.group());
			}
			
//			if(list.contains("order") && !list.contains("by")){
//				matchNum = 1;
//			}else if(list.contains("group") && !list.contains("by")){
//				matchNum = 1;
//			}else{
				matchNum =  list.size();
//			}
		}catch(Exception ex){
			Logger.getRootLogger().error("=====XSSDetectBolt=========ERROR=================" + url,ex);
		}		
		return matchNum;
	
	}
}
